/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package webprocessors;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Chris
 */
public abstract class webprocessor {
    public abstract String process(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException;
      
    protected String getUserName(HttpServletRequest request) {
        try {
            int i;
            Cookie[] cookies = request.getCookies();
            Cookie cookieUN = null;
            if(cookies.length == 0) {
                return null;
            }
            
            for(i=0; i<cookies.length; i++) {
                if(cookies[i].getName().equals("username"))
                    cookieUN = cookies[i];
            }
            return cookieUN.getValue();
        }
        catch(Exception ex) {
            return null;
        }
    }
}
